﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json;
using System.Net;
using System.IO;
using HT.DBUtility;

namespace HT.DAL
{
    public class Dal_HykblH_1
    {
     
        public Dal_HykblH_1()
        {
           
        }

        #region  Method



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(HykblHModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into hykblH(");
            strSql.Append("DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,dmbh,dmmc,khbh,khmc,kh,dh,dz,hyzk,hykye,xfzjf,jfye,zjxfjf,zjxfsj,hykzt,sffsdx,rq,sj,djyh,djsj,xgyh,mm,xgsj,bz,srmm,cfsrmm,sfz,sr,xb,ykh)");
            strSql.Append(" values (");
            strSql.Append(model.djsj + "," + model.DjBtZdh + "," + model.DjFtZdh + "," + model.DjStZdh + ",'" + model.DjState + "'," + model.DjCount + ",'" + model.dmbh + "','" + model.dmmc + "','" + model.khbh + "','" + model.khmc + "','" + model.kh + "','" + model.dh + "','" + model.dz + "'," + model.hyzk + "," + model.hykye + "," + model.xfzjf + "," + model.jfye + "," + model.zjxfjf + "," + model.zjxfsj + "," + model.hykzt + "," + model.sffsdx + ",'" + model.rq + "','" + model.sj + "','" + model.djyh + "','" + model.djsj + "','" + model.xgyh + "','" + model.mm + "','" + model.xgsj + "','" + model.bz + "','" + model.srmm + "','" + model.cfsrmm + "','" + model.sfz + "','" + model.sr + "','" + model.xb + "','" + model.ykh + "')");


            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        public int GetNewDjlsh()
        {
            string sql = " select top 1 djlsh from hykblH   order by djlsh desc";

            int djLsh = 0;

            object obj = SQLHelper.GetSingle(sql);
            if (obj != null && obj.ToString() != "")
            {
                djLsh = int.Parse(obj.ToString());
            }
            djLsh++;
            return djLsh;
        }

      

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HykblHModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hykblH set ");
            strSql.Append("DjLsh=" + model.DjLsh + ",");
            strSql.Append("DjBtZdh=" + model.DjBtZdh + ",");
            strSql.Append("DjFtZdh=" + model.DjFtZdh + ",");
            strSql.Append("DjStZdh=" + model.DjStZdh + ",");
            strSql.Append("DjState='" + model.DjState + "',");
            strSql.Append("DjCount=" + model.DjCount + ",");
            strSql.Append("dmbh='" + model.dmbh + "',");
            strSql.Append("dmmc='" + model.dmmc + "',");
            strSql.Append("khbh='" + model.khbh + "',");
            strSql.Append("khmc='" + model.khmc + "',");
            //strSql.Append("kh=@kh,");
            strSql.Append("dh='" + model.dh + "',");
            strSql.Append("dz='" + model.dz + "',");
            strSql.Append("hyzk=" + model.hyzk + ",");
            strSql.Append("hykye=hykye+" + model.hykye + ",");
            strSql.Append("xfzjf=" + model.xfzjf + ",");
            strSql.Append("jfye=" + model.jfye + ",");
            strSql.Append("zjxfjf=" + model.zjxfjf + ",");
            strSql.Append("zjxfsj=" + model.zjxfsj + ",");
            strSql.Append("hykzt='" + model.hykzt + "',");
            strSql.Append("sffsdx=" + model.sffsdx + ",");
            strSql.Append("rq='" + model.rq + "',");
            strSql.Append("sj='" + model.sj + "',");
            strSql.Append("djyh='" + model.djyh + "',");
            strSql.Append("djsj='" + model.djsj + "',");
            strSql.Append("xgyh='" + model.xgyh + "',");
            strSql.Append("mm='" + model.mm + "',");
            strSql.Append("xgsj='" + model.xgsj + "',");
            strSql.Append("bz='" + model.bz + "',");
            strSql.Append("srmm='" + model.srmm + "',");
            strSql.Append("cfsrmm='" + model.cfsrmm + "',");
            strSql.Append("sfz='" + model.sfz + "',");
            strSql.Append("sr='" + model.sr + "',");
            strSql.Append("xb='" + model.xb + "',");
            strSql.Append("ykh='" + model.ykh + "'");
            strSql.Append(" where   kh='" + model.kh + "'");


            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

  
        public int AddOrUpdateModel(HykblHModel hykblModel)
        {
            int ss = 0;


            if (hykblModel != null)
            {
                string kh = hykblModel.kh;

                if (IsExistHykblH(kh))
                {
                    //hykblModel.djyh = "";
                    //hykblModel.djsj = DateTime.Parse("1900-1-1");
                    ss = UpdateHykblHModel(hykblModel);
                }
                else
                {

                    int djlsh = GetNewDjlsh();

                    hykblModel.DjLsh = djlsh;
                    hykblModel.xgyh = "";
                    hykblModel.xgsj = DateTime.Parse("1900-1-1");
                    ss = AddHykblHModel(hykblModel);
                }

            }

            return ss;
        }
 

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddHykblHModel(HykblHModel model)
        {

            decimal sffsdx = 0;
            decimal zjxfsj = 0;
            decimal zjxfjf = 0;
            decimal jfye = 0;
            decimal xfzjf = 0;
            decimal hykye = 0;
            decimal hyzk = 0;
            if (model.sffsdx != null && model.sffsdx.ToString() != "")
            {
                sffsdx = decimal.Parse(model.sffsdx.ToString());
            }
            if (model.zjxfsj != null && model.zjxfsj.ToString() != "")
            {
                zjxfsj = decimal.Parse(model.zjxfsj.ToString());
            }
            if (model.zjxfjf != null && model.zjxfjf.ToString() != "")
            {
                zjxfjf = decimal.Parse(model.zjxfjf.ToString());
            }
            if (model.jfye != null && model.jfye.ToString() != "")
            {
                jfye = decimal.Parse(model.jfye.ToString());
            }

            if (model.xfzjf != null && model.xfzjf.ToString() != "")
            {
                xfzjf = decimal.Parse(model.xfzjf.ToString());

            }
            if (model.hykye != null && model.hykye.ToString() != "")
            {
                hykye = decimal.Parse(model.hykye.ToString());
            }

            if (model.hyzk != null && model.hyzk.ToString() != "")
            {
                hyzk = decimal.Parse(model.hyzk.ToString());
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into hykblH(");
            strSql.Append("DjLsh,dmbh,dmmc,khbh,khmc,kh,dh,dz,hyzk,hykye,xfzjf,jfye,zjxfjf,zjxfsj,hykzt,sffsdx,rq,sj,djyh,djsj,xgyh,mm,xgsj,bz,srmm,cfsrmm,sfz,sr,xb,UploadStatus,ykh)");
            strSql.Append(" values (");
            strSql.Append(model.DjLsh + ",'" + model.dmbh + "','" + model.dmmc + "','" + model.khbh + "','" + model.khmc + "','" + model.kh + "','" + model.dh + "','" + model.dz + "'," + hyzk + "," + hykye + "," + xfzjf + "," + jfye + "," + zjxfjf + "," + zjxfsj + ",'" + model.hykzt + "'," + sffsdx + ",'" + model.rq + "','" + model.sj + "','" + model.djyh + "','" + model.djsj + "','" + model.xgyh + "','" + model.mm + "','" + model.xgsj + "','" + model.bz + "','" + model.srmm + "','" + model.cfsrmm + "','" + model.sfz + "','" + model.sr + "','" + model.xb + "'," + model.UploadStatus + ",'" + model.ykh + "')");


            int rows = SQLHelper.ExecuteSql(strSql.ToString());

            return rows;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateHykblHModel(HykblHModel model)
        {
            //DjBtZdh=,DjFtZdh=,DjStZdh=,

            decimal sffsdx = 0;
            decimal zjxfsj = 0;
            decimal zjxfjf = 0;
            decimal jfye = 0;
            decimal xfzjf = 0;
            decimal hykye = 0;
            decimal hyzk = 0;
            if (model.sffsdx != null && model.sffsdx.ToString() != "")
            {
                sffsdx = decimal.Parse(model.sffsdx.ToString());
            }
            if (model.zjxfsj != null && model.zjxfsj.ToString() != "")
            {
                zjxfsj = decimal.Parse(model.zjxfsj.ToString());
            }
            if (model.zjxfjf != null && model.zjxfjf.ToString() != "")
            {
                zjxfjf = decimal.Parse(model.zjxfjf.ToString());
            }
            if (model.jfye != null && model.jfye.ToString() != "")
            {
                jfye = decimal.Parse(model.jfye.ToString());
            }

            if (model.xfzjf != null && model.xfzjf.ToString() != "")
            {
                xfzjf = decimal.Parse(model.xfzjf.ToString());

            }
            if (model.hykye != null && model.hykye.ToString() != "")
            {
                hykye = decimal.Parse(model.hykye.ToString());
            }

            if (model.hyzk != null && model.hyzk.ToString() != "")
            {
                hyzk = decimal.Parse(model.hyzk.ToString());
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hykblH set ");
            strSql.Append("dh='" + model.dh + "',");
            strSql.Append("dz='" + model.dz + "',");
            strSql.Append("hyzk=" + hyzk + ",");
            strSql.Append("hykye=hykye+" + hykye + ",");
            strSql.Append("xfzjf=" + xfzjf + ",");
            strSql.Append("jfye=" + jfye + ",");

            strSql.Append("khbh='" + model.khbh + "',");

            strSql.Append("khmc='" + model.khmc + "',");

            strSql.Append("zjxfjf=" + zjxfjf + ",");
            strSql.Append("zjxfsj=" + zjxfsj + ",");
            strSql.Append("hykzt='" + model.hykzt + "',");
            strSql.Append("sffsdx=" + sffsdx + ",");
            strSql.Append("rq='" + model.rq + "',");
            strSql.Append("sj='" + model.sj + "',");
            //strSql.Append("djyh='" + model.djyh + "',");
            //strSql.Append("djsj='" + model.djsj + "',");
            strSql.Append("xgyh='" + model.xgyh + "',");
            strSql.Append("mm='" + model.mm + "',");
            strSql.Append("xgsj='" + model.xgsj + "',");
            strSql.Append("bz='" + model.bz + "',");
            strSql.Append("srmm='" + model.srmm + "',");
            strSql.Append("cfsrmm='" + model.cfsrmm + "',");
            strSql.Append("sfz='" + model.sfz + "',");
            strSql.Append("sr='" + model.sr + "',");
            strSql.Append("xb='" + model.xb + "',");

            strSql.Append("UploadStatus='" + model.UploadStatus + "',");


            strSql.Append("ykh='" + model.ykh + "'");
            strSql.Append(" where   kh='" + model.kh + "'");

            int rows = SQLHelper.ExecuteSql(strSql.ToString());

            return rows;
        }
        /// <summary>
        /// 会员卡号是否存在
        /// </summary>
        /// <param name="kh"></param>
        /// <returns></returns>
        public bool IsExistHykblH(string kh)
        {
            string sql = "select count(*)from dbo.hykblH  where kh='" + kh + "'";

            int count = 0;
            bool b1 = false;
            try
            {
                count = int.Parse(SQLHelper.GetSingle(sql).ToString());
            }
            catch { }
            if (count > 0)
                b1 = true;
            return b1;
        }

 
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete()
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hykblH ");
            strSql.Append(" where ");
            SqlParameter[] parameters = {
};

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HykblHModel GetModel(string kh)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,dmbh,dmmc,khbh,khmc,kh,dh,dz,hyzk,hykye,xfzjf,jfye,zjxfjf,zjxfsj,hykzt,sffsdx,rq,sj,djyh,djsj,xgyh,mm,xgsj,bz,srmm,cfsrmm,sfz,sr,xb,ykh from hykblH ");
            strSql.Append(" where   kh='" + kh + "'");


            HykblHModel model = new HykblHModel();
            DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["DjLsh"] != null && dt.Rows[0]["DjLsh"].ToString() != "")
                {
                    model.DjLsh = int.Parse(dt.Rows[0]["DjLsh"].ToString());
                }
                if (dt.Rows[0]["DjBtZdh"] != null && dt.Rows[0]["DjBtZdh"].ToString() != "")
                {
                    model.DjBtZdh = int.Parse(dt.Rows[0]["DjBtZdh"].ToString());
                }
                if (dt.Rows[0]["DjFtZdh"] != null && dt.Rows[0]["DjFtZdh"].ToString() != "")
                {
                    model.DjFtZdh = int.Parse(dt.Rows[0]["DjFtZdh"].ToString());
                }
                if (dt.Rows[0]["DjStZdh"] != null && dt.Rows[0]["DjStZdh"].ToString() != "")
                {
                    model.DjStZdh = int.Parse(dt.Rows[0]["DjStZdh"].ToString());
                }
                if (dt.Rows[0]["DjState"] != null && dt.Rows[0]["DjState"].ToString() != "")
                {
                    model.DjState = dt.Rows[0]["DjState"].ToString();
                }
                if (dt.Rows[0]["DjCount"] != null && dt.Rows[0]["DjCount"].ToString() != "")
                {
                    model.DjCount = int.Parse(dt.Rows[0]["DjCount"].ToString());
                }
                if (dt.Rows[0]["dmbh"] != null && dt.Rows[0]["dmbh"].ToString() != "")
                {
                    model.dmbh = dt.Rows[0]["dmbh"].ToString();
                }
                if (dt.Rows[0]["dmmc"] != null && dt.Rows[0]["dmmc"].ToString() != "")
                {
                    model.dmmc = dt.Rows[0]["dmmc"].ToString();
                }
                if (dt.Rows[0]["khbh"] != null && dt.Rows[0]["khbh"].ToString() != "")
                {
                    model.khbh = dt.Rows[0]["khbh"].ToString();
                }
                if (dt.Rows[0]["khmc"] != null && dt.Rows[0]["khmc"].ToString() != "")
                {
                    model.khmc = dt.Rows[0]["khmc"].ToString();
                }
                if (dt.Rows[0]["kh"] != null && dt.Rows[0]["kh"].ToString() != "")
                {
                    model.kh = dt.Rows[0]["kh"].ToString();
                }
                if (dt.Rows[0]["dh"] != null && dt.Rows[0]["dh"].ToString() != "")
                {
                    model.dh = dt.Rows[0]["dh"].ToString();
                }
                if (dt.Rows[0]["dz"] != null && dt.Rows[0]["dz"].ToString() != "")
                {
                    model.dz = dt.Rows[0]["dz"].ToString();
                }
                if (dt.Rows[0]["hyzk"] != null && dt.Rows[0]["hyzk"].ToString() != "")
                {
                    model.hyzk = decimal.Parse(dt.Rows[0]["hyzk"].ToString());
                }
                if (dt.Rows[0]["hykye"] != null && dt.Rows[0]["hykye"].ToString() != "")
                {
                    model.hykye = decimal.Parse(dt.Rows[0]["hykye"].ToString());
                }
                if (dt.Rows[0]["xfzjf"] != null && dt.Rows[0]["xfzjf"].ToString() != "")
                {
                    model.xfzjf = decimal.Parse(dt.Rows[0]["xfzjf"].ToString());
                }
                if (dt.Rows[0]["jfye"] != null && dt.Rows[0]["jfye"].ToString() != "")
                {
                    model.jfye = decimal.Parse(dt.Rows[0]["jfye"].ToString());
                }
                if (dt.Rows[0]["zjxfjf"] != null && dt.Rows[0]["zjxfjf"].ToString() != "")
                {
                    model.zjxfjf = decimal.Parse(dt.Rows[0]["zjxfjf"].ToString());
                }
                if (dt.Rows[0]["zjxfsj"] != null && dt.Rows[0]["zjxfsj"].ToString() != "")
                {
                    model.zjxfsj = DateTime.Parse(dt.Rows[0]["zjxfsj"].ToString());
                }
                if (dt.Rows[0]["hykzt"] != null && dt.Rows[0]["hykzt"].ToString() != "")
                {
                    model.hykzt = dt.Rows[0]["hykzt"].ToString();
                }
                if (dt.Rows[0]["sffsdx"] != null && dt.Rows[0]["sffsdx"].ToString() != "")
                {
                    if ((dt.Rows[0]["sffsdx"].ToString() == "1") || (dt.Rows[0]["sffsdx"].ToString().ToLower() == "true"))
                    {
                        model.sffsdx = true;
                    }
                    else
                    {
                        model.sffsdx = false;
                    }
                }
                model.rq = dt.Rows[0]["rq"].ToString();
                model.sj = dt.Rows[0]["sj"].ToString();
                if (dt.Rows[0]["djyh"] != null && dt.Rows[0]["djyh"].ToString() != "")
                {
                    model.djyh = dt.Rows[0]["djyh"].ToString();
                }
                if (dt.Rows[0]["djsj"] != null && dt.Rows[0]["djsj"].ToString() != "")
                {
                    model.djsj = DateTime.Parse(dt.Rows[0]["djsj"].ToString());
                }
                if (dt.Rows[0]["xgyh"] != null && dt.Rows[0]["xgyh"].ToString() != "")
                {
                    model.xgyh = dt.Rows[0]["xgyh"].ToString();
                }
                if (dt.Rows[0]["mm"] != null && dt.Rows[0]["mm"].ToString() != "")
                {
                    model.mm = dt.Rows[0]["mm"].ToString();
                }
                if (dt.Rows[0]["xgsj"] != null && dt.Rows[0]["xgsj"].ToString() != "")
                {
                    model.xgsj = DateTime.Parse(dt.Rows[0]["xgsj"].ToString());
                }
                if (dt.Rows[0]["bz"] != null && dt.Rows[0]["bz"].ToString() != "")
                {
                    model.bz = dt.Rows[0]["bz"].ToString();
                }
                if (dt.Rows[0]["srmm"] != null && dt.Rows[0]["srmm"].ToString() != "")
                {
                    model.srmm = dt.Rows[0]["srmm"].ToString();
                }
                if (dt.Rows[0]["cfsrmm"] != null && dt.Rows[0]["cfsrmm"].ToString() != "")
                {
                    model.cfsrmm = dt.Rows[0]["cfsrmm"].ToString();
                }
                if (dt.Rows[0]["sfz"] != null && dt.Rows[0]["sfz"].ToString() != "")
                {
                    model.sfz = dt.Rows[0]["sfz"].ToString();
                }
                if (dt.Rows[0]["sr"] != null && dt.Rows[0]["sr"].ToString() != "")
                {
                    model.sr = DateTime.Parse(dt.Rows[0]["sr"].ToString());
                }
                if (dt.Rows[0]["xb"] != null && dt.Rows[0]["xb"].ToString() != "")
                {
                    model.xb = dt.Rows[0]["xb"].ToString();
                }
                if (dt.Rows[0]["ykh"] != null && dt.Rows[0]["ykh"].ToString() != "")
                {
                    model.ykh = dt.Rows[0]["ykh"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HykblHModel GetModel(string kh, string dmbh)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,dmbh,dmmc,khbh,khmc,kh,dh,dz,hyzk,hykye,xfzjf,jfye,zjxfjf,zjxfsj,hykzt,sffsdx,rq,sj,djyh,djsj,xgyh,mm,xgsj,bz,srmm,cfsrmm,sfz,sr,xb,ykh from hykblH ");
            // strSql.Append("select  top 1  khbh,khmc,kh, hyzk,hykye ,jfye  from hykblH ");

            strSql.Append(" where  ( kh='" + kh + "' or dh='" + kh + "' or  sfz='" + kh + "' )    and dmbh='" + dmbh + "'  and indexcount<>-1");


            // where  ( kh='13688454637' or dh='13688454637' or  sfz='13688454637')    and dmbh='0001'


            DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());
            HykblHModel model = new HykblHModel();

            #region model赋值

            if (dt != null && dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["DjLsh"] != null && dt.Rows[0]["DjLsh"].ToString() != "")
                {
                    model.DjLsh = int.Parse(dt.Rows[0]["DjLsh"].ToString());
                }
                if (dt.Rows[0]["DjBtZdh"] != null && dt.Rows[0]["DjBtZdh"].ToString() != "")
                {
                    model.DjBtZdh = int.Parse(dt.Rows[0]["DjBtZdh"].ToString());
                }
                if (dt.Rows[0]["DjFtZdh"] != null && dt.Rows[0]["DjFtZdh"].ToString() != "")
                {
                    model.DjFtZdh = int.Parse(dt.Rows[0]["DjFtZdh"].ToString());
                }
                if (dt.Rows[0]["DjStZdh"] != null && dt.Rows[0]["DjStZdh"].ToString() != "")
                {
                    model.DjStZdh = int.Parse(dt.Rows[0]["DjStZdh"].ToString());
                }
                if (dt.Rows[0]["DjState"] != null && dt.Rows[0]["DjState"].ToString() != "")
                {
                    model.DjState = dt.Rows[0]["DjState"].ToString();
                }
                if (dt.Rows[0]["DjCount"] != null && dt.Rows[0]["DjCount"].ToString() != "")
                {
                    model.DjCount = int.Parse(dt.Rows[0]["DjCount"].ToString());
                }
                if (dt.Rows[0]["dmbh"] != null && dt.Rows[0]["dmbh"].ToString() != "")
                {
                    model.dmbh = dt.Rows[0]["dmbh"].ToString();
                }
                if (dt.Rows[0]["dmmc"] != null && dt.Rows[0]["dmmc"].ToString() != "")
                {
                    model.dmmc = dt.Rows[0]["dmmc"].ToString();
                }
                if (dt.Rows[0]["khbh"] != null && dt.Rows[0]["khbh"].ToString() != "")
                {
                    model.khbh = dt.Rows[0]["khbh"].ToString();
                }
                if (dt.Rows[0]["khmc"] != null && dt.Rows[0]["khmc"].ToString() != "")
                {
                    model.khmc = dt.Rows[0]["khmc"].ToString();
                }
                if (dt.Rows[0]["kh"] != null && dt.Rows[0]["kh"].ToString() != "")
                {
                    model.kh = dt.Rows[0]["kh"].ToString();
                }
                if (dt.Rows[0]["dh"] != null && dt.Rows[0]["dh"].ToString() != "")
                {
                    model.dh = dt.Rows[0]["dh"].ToString();
                }
                if (dt.Rows[0]["dz"] != null && dt.Rows[0]["dz"].ToString() != "")
                {
                    model.dz = dt.Rows[0]["dz"].ToString();
                }
                if (dt.Rows[0]["hyzk"] != null && dt.Rows[0]["hyzk"].ToString() != "")
                {
                    model.hyzk = decimal.Parse(dt.Rows[0]["hyzk"].ToString());
                }
                if (dt.Rows[0]["hykye"] != null && dt.Rows[0]["hykye"].ToString() != "")
                {
                    model.hykye = decimal.Parse(dt.Rows[0]["hykye"].ToString());
                }
                if (dt.Rows[0]["xfzjf"] != null && dt.Rows[0]["xfzjf"].ToString() != "")
                {
                    model.xfzjf = decimal.Parse(dt.Rows[0]["xfzjf"].ToString());
                }
                if (dt.Rows[0]["jfye"] != null && dt.Rows[0]["jfye"].ToString() != "")
                {
                    model.jfye = decimal.Parse(dt.Rows[0]["jfye"].ToString());
                }
                if (dt.Rows[0]["zjxfjf"] != null && dt.Rows[0]["zjxfjf"].ToString() != "")
                {
                    model.zjxfjf = decimal.Parse(dt.Rows[0]["zjxfjf"].ToString());
                }
                if (dt.Rows[0]["zjxfsj"] != null && dt.Rows[0]["zjxfsj"].ToString() != "")
                {
                    model.zjxfsj = DateTime.Parse(dt.Rows[0]["zjxfsj"].ToString());
                }
                if (dt.Rows[0]["hykzt"] != null && dt.Rows[0]["hykzt"].ToString() != "")
                {
                    model.hykzt = dt.Rows[0]["hykzt"].ToString();
                }
                if (dt.Rows[0]["sffsdx"] != null && dt.Rows[0]["sffsdx"].ToString() != "")
                {
                    if ((dt.Rows[0]["sffsdx"].ToString() == "1") || (dt.Rows[0]["sffsdx"].ToString().ToLower() == "true"))
                    {
                        model.sffsdx = true;
                    }
                    else
                    {
                        model.sffsdx = false;
                    }
                }
                model.rq = dt.Rows[0]["rq"].ToString();
                model.sj = dt.Rows[0]["sj"].ToString();
                if (dt.Rows[0]["djyh"] != null && dt.Rows[0]["djyh"].ToString() != "")
                {
                    model.djyh = dt.Rows[0]["djyh"].ToString();
                }
                if (dt.Rows[0]["djsj"] != null && dt.Rows[0]["djsj"].ToString() != "")
                {
                    model.djsj = DateTime.Parse(dt.Rows[0]["djsj"].ToString());
                }
                if (dt.Rows[0]["xgyh"] != null && dt.Rows[0]["xgyh"].ToString() != "")
                {
                    model.xgyh = dt.Rows[0]["xgyh"].ToString();
                }
                if (dt.Rows[0]["mm"] != null && dt.Rows[0]["mm"].ToString() != "")
                {
                    model.mm = dt.Rows[0]["mm"].ToString();
                }
                if (dt.Rows[0]["xgsj"] != null && dt.Rows[0]["xgsj"].ToString() != "")
                {
                    model.xgsj = DateTime.Parse(dt.Rows[0]["xgsj"].ToString());
                }
                if (dt.Rows[0]["bz"] != null && dt.Rows[0]["bz"].ToString() != "")
                {
                    model.bz = dt.Rows[0]["bz"].ToString();
                }
                if (dt.Rows[0]["srmm"] != null && dt.Rows[0]["srmm"].ToString() != "")
                {
                    model.srmm = dt.Rows[0]["srmm"].ToString();
                }
                if (dt.Rows[0]["cfsrmm"] != null && dt.Rows[0]["cfsrmm"].ToString() != "")
                {
                    model.cfsrmm = dt.Rows[0]["cfsrmm"].ToString();
                }
                if (dt.Rows[0]["sfz"] != null && dt.Rows[0]["sfz"].ToString() != "")
                {
                    model.sfz = dt.Rows[0]["sfz"].ToString();
                }
                if (dt.Rows[0]["sr"] != null && dt.Rows[0]["sr"].ToString() != "")
                {
                    model.sr = DateTime.Parse(dt.Rows[0]["sr"].ToString());
                }
                if (dt.Rows[0]["xb"] != null && dt.Rows[0]["xb"].ToString() != "")
                {
                    model.xb = dt.Rows[0]["xb"].ToString();
                }
                if (dt.Rows[0]["ykh"] != null && dt.Rows[0]["ykh"].ToString() != "")
                {
                    model.ykh = dt.Rows[0]["ykh"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
            #endregion
        }


        public int HykCZ(string kh, decimal je, string dmbh, string yyybh)
        {
            List<string> sqlList = new List<string>();

            string sql = "insert into hykczjl(Hykh,Sj,Je,Dmbh,Yyy,UploadStatus) values('" + kh + "','" + DateTime.Now.ToString("yyyy-MM-") + "'," + je + ",'" + dmbh + "','" + yyybh + "',0)";
            sqlList.Add(sql);
            string sql2 = " update hykblH   set hykye=hykye+" + je + "    where kh='" + kh + "'";
            sqlList.Add(sql2);

            int ss = SQLHelper.ExecuteSqlTran(sqlList);

            return ss;
        }



        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select DjLsh,DjBtZdh,DjFtZdh,DjStZdh,DjState,DjCount,dmbh,dmmc,khbh,khmc,kh,dh,dz,hyzk,hykye,xfzjf,jfye,zjxfjf,zjxfsj,hykzt,sffsdx,rq,sj,djyh,djsj,xgyh,mm,xgsj,bz,srmm,cfsrmm,sfz,sr,xb,ykh ");
            strSql.Append(" FROM hykblH ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLHelper.ExecuteDt(strSql.ToString());
        }



        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM hykblH ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = SQLHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }



        public DataSet GetHykblHData()
        {
            string sql = "select *from dbo.hykblH  where uploadstatus is null or uploadstatus=0";
            DataSet ds = SQLHelper.ExecuteDs(sql);
            return ds;
        }
        public DataSet GetHykczjlData()
        {
            string sql = "select *from dbo.hykczjl where uploadstatus is null or uploadstatus=0";
            DataSet ds = SQLHelper.ExecuteDs(sql);
            return ds;
        }
  
        public int ExecuteSqlTran(List<string> sqlList)
        {
            int ss = SQLHelper.ExecuteSqlTran(sqlList);
            return ss;
        }
        public int SaveHykblHData(List<string> sqlList)
        {
            int s1 = SQLHelper.ExecuteSqlTran(sqlList);
            return s1;
        }



        #endregion  Method
         
    }
}
